package com.crealth.model;

import java.io.Serializable;
import java.sql.Timestamp;

import com.alibaba.fastjson.JSONObject;
import com.crealth.Config;
import com.crealth.utils.PhoneNumDecode;

public class ClienteleInfoModel implements Serializable {
	private static final long serialVersionUID = 54945121L;
	
	private int id;
	private String inputDate;
	private String Type;
	private String Name;
	private String Mobi;
	private String Tele;
	private String Hous;
	private String Addr;
	private String Unit; 
	private String IdNo;
	private String Noti;
	private String Dscr;
	private int createrUserID;
	private Timestamp DispatchedDate;
	private int DispatchedUserID;
	
	public ClienteleInfoModel() {
		id = 0;
		inputDate = "";
		Type = "";
		Name = "";
		Mobi = "";
		Tele = "";
		Hous = "";
		Addr = "";
		Unit = ""; 
		IdNo = "";
		Noti = "";
		Dscr = "";
		createrUserID = 0;
		DispatchedDate = null;
		DispatchedUserID = 0;
	}
	
	public boolean isEmpty() {
		if (Mobi.length() == 0 && Name.length() == 0 && Addr.length() == 0) {
			return true;
		}
		
		return false;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getInputDate() {
		return inputDate;
	}
	public void setInputDate(String inputDate) {
		this.inputDate = inputDate;
	}
	public String getType() {
		return Type;
	}
	public void setType(String type) {
		Type = type;
	}
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		if (null == name) {
			name = "";
		}
		if (name.indexOf(',') > 0) {
			name = name.split(",")[0];
		}
		if (name.indexOf('，') > 0) {
			name = name.split("，")[0];
		}
		if (name.length() > 6) {
			name = name.substring(0, 6);
		}
		Name = name;
	}
	public String getMobi() {
		return Mobi;
	}
	public void setMobi(String mobi) {
		Mobi = mobi;
	}
	public String getTele() {
		return Tele;
	}
	public void setTele(String tele) {
		Tele = tele;
	}
	public String getHous() {
		return Hous;
	}
	public void setHous(String hous) {
		Hous = hous;
	}
	public String getAddr() {
		return Addr;
	}
	public void setAddr(String addr) {
		Addr = addr;
	}
	public String getUnit() {
		return Unit;
	}
	public void setUnit(String unit) {
		Unit = unit;
	}
	public String getIdNo() {
		return IdNo;
	}
	public void setIdNo(String idNo) {
		IdNo = idNo;
	}
	public String getNoti() {
		return Noti;
	}
	public void setNoti(String noti) {
		Noti = noti;
	}
	public String getDscr() {
		return Dscr;
	}
	public void setDscr(String dscr) {
		Dscr = dscr;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public int getCreaterUserID() {
		return createrUserID;
	}

	public void setCreaterUserID(int createrUserID) {
		this.createrUserID = createrUserID;
	}

	public Timestamp getDispatchedDate() {
		return DispatchedDate;
	}

	public void setDispatchedDate(Timestamp dispatchedDate) {
		DispatchedDate = dispatchedDate;
	}

	public int getDispatchedUserID() {
		return DispatchedUserID;
	}

	public void setDispatchedUserID(int dispatchedUserID) {
		DispatchedUserID = dispatchedUserID;
	}
	
	public JSONObject toJSONObjectOnlyMobi() {
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("Name", Name);
		String strMobi = Mobi;
		if (Config.mobiPhoneEncrypt) {
			strMobi = PhoneNumDecode.decryptPhone(Mobi);
		}		
		jsonObj.put("Mobi", strMobi);
		
		return jsonObj;
	}

	public JSONObject toJSONObject() {
		JSONObject jsonObj = new JSONObject();
		jsonObj.put("id", id);
		jsonObj.put("inputDate", inputDate);
		jsonObj.put("Type", Type);
		jsonObj.put("Name", Name);		
		String strMobi = Mobi;
		if (Config.mobiPhoneEncrypt) {
			strMobi = PhoneNumDecode.decryptPhone(Mobi);
		}		
		jsonObj.put("Mobi", strMobi);
		jsonObj.put("Tele", Tele);
		jsonObj.put("Hous", Hous);
		jsonObj.put("Addr", Addr);
		jsonObj.put("Unit", Unit);
		jsonObj.put("IdNo", IdNo);
		jsonObj.put("Noti", Noti);
		jsonObj.put("Dscr", Dscr);
		return jsonObj;
	}
	
	public void fromJson(JSONObject jsonObj) {
		if (jsonObj.containsKey("id")) {
			id = jsonObj.getInteger("id");
		}
		if (jsonObj.containsKey("inputDate")) {
			inputDate = jsonObj.getString("inputDate").trim();
		}
		if (jsonObj.containsKey("Type")) {
			Type = jsonObj.getString("Type").trim();
		}
		if (jsonObj.containsKey("Name")) {
			setName(jsonObj.getString("Name").trim());			
		}
		if (jsonObj.containsKey("Mobi")) {
			Mobi = jsonObj.getString("Mobi").trim();
		}
		if (jsonObj.containsKey("Tele")) {
			Tele = jsonObj.getString("Tele").trim();
		}
		if (jsonObj.containsKey("Hous")) {
			Hous = jsonObj.getString("Hous").trim();
		}
		if (jsonObj.containsKey("Addr")) {
			Addr = jsonObj.getString("Addr").trim();
		}
		if (jsonObj.containsKey("Unit")) {
			Unit = jsonObj.getString("Unit").trim();
		}
		if (jsonObj.containsKey("IdNo")) {
			IdNo = jsonObj.getString("IdNo").trim();
		}
		if (jsonObj.containsKey("Noti")) {
			Noti = jsonObj.getString("Noti").trim();
		}
		if (jsonObj.containsKey("Dscr")) {
			Dscr = jsonObj.getString("Dscr").trim();
		}
	}
}
